import Taro from "@tarojs/taro"

const tips = key => Taro.showToast({
    title: `暂无本地(${key})缓存`,
    icon: "none",
    mask: true
})

export default async (key, data) => {
    console.log(key);

    if(data){
        return await Taro.setStorage({ key, data }).then(row => {
            return row?row.data:tips(key)
        }).catch(err=>tips(err))
        // todo 查看err提供的内容，然后将内容传出
    }else if(key){
        return await Taro.getStorage({key}).then(row => {
            if(row){
                return row.data
            }else{
                tips(key)
            }
        }).catch(err => tips(err.errMsg))
    }else{
        Taro.clearStorageSync().then({success:true,message:'localStorage清理成功！'})
    }
}